package com.bnzj.core.export;

import java.util.Comparator;
import java.util.function.Function;

import lombok.Getter;
import lombok.Setter;

/**
 * @author barry
 * @date 2019-10-11
 */
@Setter
@Getter
public class Column implements Comparator<Column>, Comparable<Column> {
    private final String field;
    private final String title;
    private int fieldIndex;//列顺序
    private int width = 50;//列宽
    private boolean visible;//是否显示
    private Function<Object, String> function;//数据转换函数
    
    public Column(String field, String title, int fieldIndex) {
        this(field, title, fieldIndex, null);
    }
    
    public Column(String field, String title, int fieldIndex, Function<Object, String> function) {
        this(field, title, fieldIndex, 50, true, function);
    }
    
    public Column(String field, String title, int fieldIndex, int width, boolean visible, Function<Object, String> function) {
        this.field = field;
        this.title = title;
        this.fieldIndex = fieldIndex;
        this.width = width;
        this.visible = visible;
        this.function = function;
    }
    
    /* (non-Javadoc)
     * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
     */
    @Override
    public int compare(Column o1, Column o2) {
        return o1.fieldIndex - o2.fieldIndex; 
    }

    /* (non-Javadoc)
     * @see java.lang.Comparable#compareTo(java.lang.Object)
     */
    @Override
    public int compareTo(Column o) {
        return compare(this, o);
    }
}
